package com.zbkj.crmeb.agent.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.agent.model.Agent;
import com.zbkj.crmeb.agent.request.AddAgentRequest;
import com.zbkj.crmeb.agent.request.AdminAgentRequest;
import com.zbkj.crmeb.agent.request.AgentListRequest;
import com.zbkj.crmeb.agent.request.SettlementRequest;
import com.zbkj.crmeb.agent.response.DropDownAgentsResponse;
import com.zbkj.crmeb.agent.response.SettlementResponse;
import com.zbkj.crmeb.agent.service.AgentService;
import com.zbkj.crmeb.agent.vo.AgentVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 服务商表 前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2022-02-15
 */
@RestController
@RequestMapping("api/admin/agent")
@Api(tags = "总后台-服务商配置")
public class AgentController {

    @Autowired
    private AgentService agentService;

    /**
     * 服务商列表
     */
    @ApiOperation(value = "服务商列表")
    @GetMapping(value = "/list")
    public CommonResult<CommonPage<Agent>> getAgentList(PageParamRequest request){
        return CommonResult.success(CommonPage.restPage(agentService.getAgentList(request)));
    }

    /**
     * 服务商列表
     */
    @ApiOperation(value = "财务服务商列表")
    @GetMapping(value = "/financial/list")
    public CommonResult<CommonPage<AgentVo>> getFinancialAgentList(AgentListRequest request){
        return CommonResult.success(CommonPage.restPage(agentService.getFinancialAgentList(request)));
    }

    /**
     * 根据id查询服务商信息
     */
    @ApiOperation(value = "根据id查询服务商信息")
    @GetMapping(value = "/info/{id}")
    public CommonResult<AgentVo> getAgentById(@PathVariable("id") Integer id){
        return agentService.getAgentById(id);
    }

    /**
     * 添加服务商
     */
    @ApiOperation(value = "添加服务商")
    @PostMapping(value = "/add")
    public CommonResult<String> addAgent(@RequestBody @Validated AddAgentRequest request){
        return agentService.addAgent(request);
    }

    /**
     * 编辑服务商
     */
    @ApiOperation(value = "编辑服务商")
    @PutMapping(value = "/update")
    public CommonResult<String> updateAgent(@RequestBody @Validated AddAgentRequest request){
        return agentService.updateAgent(request);
    }

    /**
     * 删除服务商
     */
    @ApiOperation(value = "删除服务商")
    @DeleteMapping(value = "/delete/{id}")
    public CommonResult<String> deleteAgent(@PathVariable("id") Integer id){
        return agentService.deleteAgent(id);
    }

    /**
     * 服务商下拉框
     */
    @ApiOperation(value = "服务商下拉框")
    @GetMapping(value = "/drop-down-agents/{level}")
    @ApiImplicitParam(name = "level", value = "级别 1:一级服务商 2:二级服务商", required = true, allowableValues = "range[1,2]")
    public CommonResult<List<DropDownAgentsResponse>> dropDownAgents(@PathVariable("level") Integer level){
        return agentService.dropDownAgents(level);
    }

    @ApiOperation(value = "服务商结算列表")
    @GetMapping(value = "/settlement")
    public CommonResult<CommonPage<SettlementResponse>>  settlement(SettlementRequest request){
        return CommonResult.success(CommonPage.restPage(agentService.settlement(request)));
    }

    /**
     * 管理员服务商下拉框
     * @param request 搜索条件
     */
    @ApiOperation(value = "管理员服务商下拉框")
    @GetMapping(value = "/admin/selectList")
    public CommonResult<List<DropDownAgentsResponse>> listDropDownAgents(@Validated AdminAgentRequest request) {
        return agentService.listDropDownAgents(request);

    }

}

